﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Max.PH5_2006.ShoppingSite.API.MyFilter
{
    //public class MyExceptionFilterHandler : 
    //    I Exception Filter,
    //    IActionFilter,
    //    IResourceFilter,
    //    IAuthorizationFilter,
    //    IResultFilter
    //{

    //}


    public class MyExceptionFilterHandler : IExceptionFilter
    {
        NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
        public void OnException(ExceptionContext context)
        {
            if (!context.ExceptionHandled)
            {
                //给我们的api的友好提示
                context.Result = new ObjectResult(
                    new { code = 500, message = "服务器内部错误，请与管理员联系" }
                 );

                //帮助我们开发或运营找到真正的错误原因
                log.Error(context.Exception.Message);
            }

            context.ExceptionHandled = true;
        }
    }
}
